//
//  ALAsset+SwitchUrl.m
//  triphare
//
//  Created by mac mini03 on 15/2/4.
//  Copyright (c) 2015年 ___LOTTO___. All rights reserved.
//

#import "ALAsset+Extension.h"

@implementation ALAsset (SwitchUrl)

+ (ALAsset *)assetWithUrl:(NSString *)url {
    ALAssetsLibrary   *lib = [[ALAssetsLibrary alloc] init];
    __block ALAsset *assett;
    [lib assetForURL:[NSURL URLWithString:url] resultBlock:^(ALAsset *asset){
        //在这里使用asset来获取图片
        assett = asset;
    }
    failureBlock:^(NSError *error){
        
    }];
    
    return assett;
}

+ (NSString *)assetUrlWithAsset:(ALAsset *)asset {
//    NSString *assetUrl = [[[asset defaultRepresentation] url] description];
    NSString *assetUrl = [(NSURL*)[asset valueForProperty:ALAssetPropertyAssetURL] absoluteString];
    
    return assetUrl;
}

//- (ALAsset *)assetWithUrl:(NSString *)url {
////    ALAsset *asset = [asset valueForProperty:url];
//    
////    return asset;
//}

+ (UIImage *)imageFromAsset:(ALAsset *)asset
{
    ALAssetRepresentation *assetRep = [asset defaultRepresentation];
    CGImageRef imgRef = [assetRep fullScreenImage];
    UIImage *img = [UIImage imageWithCGImage:imgRef
                                       scale:assetRep.scale
                                 orientation:UIImageOrientationUp];
    return img;
}


@end
